<HTML>
<BODY BGCOLOR="white">
<PRE>
<FONT color="green">001</FONT>    /*<a name="line.1"></a>
<FONT color="green">002</FONT>     * Licensed to the Apache Software Foundation (ASF) under one or more<a name="line.2"></a>
<FONT color="green">003</FONT>     * contributor license agreements.  See the NOTICE file distributed with<a name="line.3"></a>
<FONT color="green">004</FONT>     * this work for additional information regarding copyright ownership.<a name="line.4"></a>
<FONT color="green">005</FONT>     * The ASF licenses this file to You under the Apache License, Version 2.0<a name="line.5"></a>
<FONT color="green">006</FONT>     * (the "License"); you may not use this file except in compliance with<a name="line.6"></a>
<FONT color="green">007</FONT>     * the License.  You may obtain a copy of the License at<a name="line.7"></a>
<FONT color="green">008</FONT>     * <a name="line.8"></a>
<FONT color="green">009</FONT>     *      http://www.apache.org/licenses/LICENSE-2.0<a name="line.9"></a>
<FONT color="green">010</FONT>     * <a name="line.10"></a>
<FONT color="green">011</FONT>     * Unless required by applicable law or agreed to in writing, software<a name="line.11"></a>
<FONT color="green">012</FONT>     * distributed under the License is distributed on an "AS IS" BASIS,<a name="line.12"></a>
<FONT color="green">013</FONT>     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<a name="line.13"></a>
<FONT color="green">014</FONT>     * See the License for the specific language governing permissions and<a name="line.14"></a>
<FONT color="green">015</FONT>     * limitations under the License.<a name="line.15"></a>
<FONT color="green">016</FONT>     */<a name="line.16"></a>
<FONT color="green">017</FONT>    <a name="line.17"></a>
<FONT color="green">018</FONT>    package org.apache.commons.codec.binary;<a name="line.18"></a>
<FONT color="green">019</FONT>    <a name="line.19"></a>
<FONT color="green">020</FONT>    /**<a name="line.20"></a>
<FONT color="green">021</FONT>     * Provides Base32 encoding and decoding as defined by &lt;a href="http://www.ietf.org/rfc/rfc4648.txt"&gt;RFC 4648&lt;/a&gt;.<a name="line.21"></a>
<FONT color="green">022</FONT>     * <a name="line.22"></a>
<FONT color="green">023</FONT>     * &lt;p&gt;<a name="line.23"></a>
<FONT color="green">024</FONT>     * The class can be parameterized in the following manner with various constructors:<a name="line.24"></a>
<FONT color="green">025</FONT>     * &lt;ul&gt;<a name="line.25"></a>
<FONT color="green">026</FONT>     * &lt;li&gt;Whether to use the "base32hex" variant instead of the default "base32"&lt;/li&gt;<a name="line.26"></a>
<FONT color="green">027</FONT>     * &lt;li&gt;Line length: Default 76. Line length that aren't multiples of 8 will still essentially end up being multiples of<a name="line.27"></a>
<FONT color="green">028</FONT>     * 8 in the encoded data.<a name="line.28"></a>
<FONT color="green">029</FONT>     * &lt;li&gt;Line separator: Default is CRLF ("\r\n")&lt;/li&gt;<a name="line.29"></a>
<FONT color="green">030</FONT>     * &lt;/ul&gt;<a name="line.30"></a>
<FONT color="green">031</FONT>     * &lt;/p&gt;<a name="line.31"></a>
<FONT color="green">032</FONT>     * &lt;p&gt;<a name="line.32"></a>
<FONT color="green">033</FONT>     * This class operates directly on byte streams, and not character streams.<a name="line.33"></a>
<FONT color="green">034</FONT>     * &lt;/p&gt;<a name="line.34"></a>
<FONT color="green">035</FONT>     * &lt;p&gt;<a name="line.35"></a>
<FONT color="green">036</FONT>     * This class is not thread-safe. Each thread should use its own instance.<a name="line.36"></a>
<FONT color="green">037</FONT>     * &lt;/p&gt;<a name="line.37"></a>
<FONT color="green">038</FONT>     * <a name="line.38"></a>
<FONT color="green">039</FONT>     * @see &lt;a href="http://www.ietf.org/rfc/rfc4648.txt"&gt;RFC 4648&lt;/a&gt;<a name="line.39"></a>
<FONT color="green">040</FONT>     * <a name="line.40"></a>
<FONT color="green">041</FONT>     * @since 1.5<a name="line.41"></a>
<FONT color="green">042</FONT>     * @version $Revision: 1080712 $<a name="line.42"></a>
<FONT color="green">043</FONT>     */<a name="line.43"></a>
<FONT color="green">044</FONT>    public class Base32 extends BaseNCodec {<a name="line.44"></a>
<FONT color="green">045</FONT>    <a name="line.45"></a>
<FONT color="green">046</FONT>        /**<a name="line.46"></a>
<FONT color="green">047</FONT>         * BASE32 characters are 5 bits in length. <a name="line.47"></a>
<FONT color="green">048</FONT>         * They are formed by taking a block of five octets to form a 40-bit string, <a name="line.48"></a>
<FONT color="green">049</FONT>         * which is converted into eight BASE32 characters.<a name="line.49"></a>
<FONT color="green">050</FONT>         */<a name="line.50"></a>
<FONT color="green">051</FONT>        private static final int BITS_PER_ENCODED_BYTE = 5;<a name="line.51"></a>
<FONT color="green">052</FONT>        private static final int BYTES_PER_ENCODED_BLOCK = 8;<a name="line.52"></a>
<FONT color="green">053</FONT>        private static final int BYTES_PER_UNENCODED_BLOCK = 5;<a name="line.53"></a>
<FONT color="green">054</FONT>    <a name="line.54"></a>
<FONT color="green">055</FONT>        /**<a name="line.55"></a>
<FONT color="green">056</FONT>         * Chunk separator per RFC 2045 section 2.1.<a name="line.56"></a>
<FONT color="green">057</FONT>         *<a name="line.57"></a>
<FONT color="green">058</FONT>         * @see &lt;a href="http://www.ietf.org/rfc/rfc2045.txt"&gt;RFC 2045 section 2.1&lt;/a&gt;<a name="line.58"></a>
<FONT color="green">059</FONT>         */<a name="line.59"></a>
<FONT color="green">060</FONT>        private static final byte[] CHUNK_SEPARATOR = {'\r', '\n'};<a name="line.60"></a>
<FONT color="green">061</FONT>    <a name="line.61"></a>
<FONT color="green">062</FONT>        /**<a name="line.62"></a>
<FONT color="green">063</FONT>         * This array is a lookup table that translates Unicode characters drawn from the "Base32 Alphabet" (as specified in<a name="line.63"></a>
<FONT color="green">064</FONT>         * Table 3 of RFC 2045) into their 5-bit positive integer equivalents. Characters that are not in the Base32<a name="line.64"></a>
<FONT color="green">065</FONT>         * alphabet but fall within the bounds of the array are translated to -1.<a name="line.65"></a>
<FONT color="green">066</FONT>         * <a name="line.66"></a>
<FONT color="green">067</FONT>         */<a name="line.67"></a>
<FONT color="green">068</FONT>        private static final byte[] DECODE_TABLE = {<a name="line.68"></a>
<FONT color="green">069</FONT>             //  0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F<a name="line.69"></a>
<FONT color="green">070</FONT>                -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 00-0f<a name="line.70"></a>
<FONT color="green">071</FONT>                -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 10-1f<a name="line.71"></a>
<FONT color="green">072</FONT>                -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 63, // 20-2f<a name="line.72"></a>
<FONT color="green">073</FONT>                -1, -1, 26, 27, 28, 29, 30, 31, -1, -1, -1, -1, -1, -1, -1, -1, // 30-3f 2-7<a name="line.73"></a>
<FONT color="green">074</FONT>                -1,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, // 40-4f A-N<a name="line.74"></a>
<FONT color="green">075</FONT>                15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,                     // 50-5a O-Z<a name="line.75"></a>
<FONT color="green">076</FONT>        };<a name="line.76"></a>
<FONT color="green">077</FONT>    <a name="line.77"></a>
<FONT color="green">078</FONT>        /**<a name="line.78"></a>
<FONT color="green">079</FONT>         * This array is a lookup table that translates 5-bit positive integer index values into their "Base32 Alphabet"<a name="line.79"></a>
<FONT color="green">080</FONT>         * equivalents as specified in Table 3 of RFC 2045.<a name="line.80"></a>
<FONT color="green">081</FONT>         */<a name="line.81"></a>
<FONT color="green">082</FONT>        private static final byte[] ENCODE_TABLE = {<a name="line.82"></a>
<FONT color="green">083</FONT>                'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',<a name="line.83"></a>
<FONT color="green">084</FONT>                'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',<a name="line.84"></a>
<FONT color="green">085</FONT>                '2', '3', '4', '5', '6', '7',<a name="line.85"></a>
<FONT color="green">086</FONT>        };<a name="line.86"></a>
<FONT color="green">087</FONT>    <a name="line.87"></a>
<FONT color="green">088</FONT>        /**<a name="line.88"></a>
<FONT color="green">089</FONT>         * This array is a lookup table that translates Unicode characters drawn from the "Base32 |Hex Alphabet" (as specified in<a name="line.89"></a>
<FONT color="green">090</FONT>         * Table 3 of RFC 2045) into their 5-bit positive integer equivalents. Characters that are not in the Base32 Hex<a name="line.90"></a>
<FONT color="green">091</FONT>         * alphabet but fall within the bounds of the array are translated to -1.<a name="line.91"></a>
<FONT color="green">092</FONT>         * <a name="line.92"></a>
<FONT color="green">093</FONT>         */<a name="line.93"></a>
<FONT color="green">094</FONT>        private static final byte[] HEX_DECODE_TABLE = {<a name="line.94"></a>
<FONT color="green">095</FONT>             //  0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F<a name="line.95"></a>
<FONT color="green">096</FONT>                -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 00-0f<a name="line.96"></a>
<FONT color="green">097</FONT>                -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 10-1f<a name="line.97"></a>
<FONT color="green">098</FONT>                -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 63, // 20-2f<a name="line.98"></a>
<FONT color="green">099</FONT>                 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, -1, -1, -1, -1, -1, -1, // 30-3f 2-7<a name="line.99"></a>
<FONT color="green">100</FONT>                -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, // 40-4f A-N<a name="line.100"></a>
<FONT color="green">101</FONT>                25, 26, 27, 28, 29, 30, 31, 32,                                 // 50-57 O-V<a name="line.101"></a>
<FONT color="green">102</FONT>        };<a name="line.102"></a>
<FONT color="green">103</FONT>    <a name="line.103"></a>
<FONT color="green">104</FONT>        /**<a name="line.104"></a>
<FONT color="green">105</FONT>         * This array is a lookup table that translates 5-bit positive integer index values into their "Base32 Hex Alphabet"<a name="line.105"></a>
<FONT color="green">106</FONT>         * equivalents as specified in Table 3 of RFC 2045.<a name="line.106"></a>
<FONT color="green">107</FONT>         */<a name="line.107"></a>
<FONT color="green">108</FONT>        private static final byte[] HEX_ENCODE_TABLE = {<a name="line.108"></a>
<FONT color="green">109</FONT>                '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', <a name="line.109"></a>
<FONT color="green">110</FONT>                'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',<a name="line.110"></a>
<FONT color="green">111</FONT>                'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',<a name="line.111"></a>
<FONT color="green">112</FONT>        };<a name="line.112"></a>
<FONT color="green">113</FONT>    <a name="line.113"></a>
<FONT color="green">114</FONT>        /** Mask used to extract 5 bits, used when encoding Base32 bytes */<a name="line.114"></a>
<FONT color="green">115</FONT>        private static final int MASK_5BITS = 0x1f;<a name="line.115"></a>
<FONT color="green">116</FONT>    <a name="line.116"></a>
<FONT color="green">117</FONT>        // The static final fields above are used for the original static byte[] methods on Base32.<a name="line.117"></a>
<FONT color="green">118</FONT>        // The private member fields below are used with the new streaming approach, which requires<a name="line.118"></a>
<FONT color="green">119</FONT>        // some state be preserved between calls of encode() and decode().<a name="line.119"></a>
<FONT color="green">120</FONT>    <a name="line.120"></a>
<FONT color="green">121</FONT>        /**<a name="line.121"></a>
<FONT color="green">122</FONT>         * Place holder for the bytes we're dealing with for our based logic. <a name="line.122"></a>
<FONT color="green">123</FONT>         * Bitwise operations store and extract the encoding or decoding from this variable.<a name="line.123"></a>
<FONT color="green">124</FONT>         */<a name="line.124"></a>
<FONT color="green">125</FONT>        private long bitWorkArea;<a name="line.125"></a>
<FONT color="green">126</FONT>    <a name="line.126"></a>
<FONT color="green">127</FONT>        /**<a name="line.127"></a>
<FONT color="green">128</FONT>         * Convenience variable to help us determine when our buffer is going to run out of room and needs resizing.<a name="line.128"></a>
<FONT color="green">129</FONT>         * &lt;code&gt;decodeSize = {@link BYTES_PER_ENCODED_BLOCK} - 1 + lineSeparator.length;&lt;/code&gt;<a name="line.129"></a>
<FONT color="green">130</FONT>         */<a name="line.130"></a>
<FONT color="green">131</FONT>        private final int decodeSize;<a name="line.131"></a>
<FONT color="green">132</FONT>    <a name="line.132"></a>
<FONT color="green">133</FONT>        /**<a name="line.133"></a>
<FONT color="green">134</FONT>         * Decode table to use.<a name="line.134"></a>
<FONT color="green">135</FONT>         */<a name="line.135"></a>
<FONT color="green">136</FONT>        private final byte[] decodeTable;<a name="line.136"></a>
<FONT color="green">137</FONT>    <a name="line.137"></a>
<FONT color="green">138</FONT>        /**<a name="line.138"></a>
<FONT color="green">139</FONT>         * Convenience variable to help us determine when our buffer is going to run out of room and needs resizing.<a name="line.139"></a>
<FONT color="green">140</FONT>         * &lt;code&gt;encodeSize = {@link BYTES_PER_ENCODED_BLOCK} + lineSeparator.length;&lt;/code&gt;<a name="line.140"></a>
<FONT color="green">141</FONT>         */<a name="line.141"></a>
<FONT color="green">142</FONT>        private final int encodeSize;<a name="line.142"></a>
<FONT color="green">143</FONT>    <a name="line.143"></a>
<FONT color="green">144</FONT>        /**<a name="line.144"></a>
<FONT color="green">145</FONT>         * Encode table to use.<a name="line.145"></a>
<FONT color="green">146</FONT>         */<a name="line.146"></a>
<FONT color="green">147</FONT>        private final byte[] encodeTable;<a name="line.147"></a>
<FONT color="green">148</FONT>    <a name="line.148"></a>
<FONT color="green">149</FONT>        /**<a name="line.149"></a>
<FONT color="green">150</FONT>         * Line separator for encoding. Not used when decoding. Only used if lineLength &gt; 0.<a name="line.150"></a>
<FONT color="green">151</FONT>         */<a name="line.151"></a>
<FONT color="green">152</FONT>        private final byte[] lineSeparator;<a name="line.152"></a>
<FONT color="green">153</FONT>    <a name="line.153"></a>
<FONT color="green">154</FONT>        /**<a name="line.154"></a>
<FONT color="green">155</FONT>         * Creates a Base32 codec used for decoding and encoding.<a name="line.155"></a>
<FONT color="green">156</FONT>         * &lt;p&gt;<a name="line.156"></a>
<FONT color="green">157</FONT>         * When encoding the line length is 0 (no chunking).<a name="line.157"></a>
<FONT color="green">158</FONT>         * &lt;/p&gt;<a name="line.158"></a>
<FONT color="green">159</FONT>         * <a name="line.159"></a>
<FONT color="green">160</FONT>         */<a name="line.160"></a>
<FONT color="green">161</FONT>        public Base32() {<a name="line.161"></a>
<FONT color="green">162</FONT>            this(false);<a name="line.162"></a>
<FONT color="green">163</FONT>        }<a name="line.163"></a>
<FONT color="green">164</FONT>    <a name="line.164"></a>
<FONT color="green">165</FONT>        /**<a name="line.165"></a>
<FONT color="green">166</FONT>         * Creates a Base32 codec used for decoding and encoding.<a name="line.166"></a>
<FONT color="green">167</FONT>         * &lt;p&gt;<a name="line.167"></a>
<FONT color="green">168</FONT>         * When encoding the line length is 0 (no chunking).<a name="line.168"></a>
<FONT color="green">169</FONT>         * &lt;/p&gt;<a name="line.169"></a>
<FONT color="green">170</FONT>         * @param useHex if &lt;code&gt;true&lt;/code&gt; then use Base32 Hex alphabet<a name="line.170"></a>
<FONT color="green">171</FONT>         */<a name="line.171"></a>
<FONT color="green">172</FONT>        public Base32(boolean useHex) {<a name="line.172"></a>
<FONT color="green">173</FONT>            this(0, null, useHex);<a name="line.173"></a>
<FONT color="green">174</FONT>        }<a name="line.174"></a>
<FONT color="green">175</FONT>    <a name="line.175"></a>
<FONT color="green">176</FONT>        /**<a name="line.176"></a>
<FONT color="green">177</FONT>         * Creates a Base32 codec used for decoding and encoding.<a name="line.177"></a>
<FONT color="green">178</FONT>         * &lt;p&gt;<a name="line.178"></a>
<FONT color="green">179</FONT>         * When encoding the line length is given in the constructor, the line separator is CRLF.<a name="line.179"></a>
<FONT color="green">180</FONT>         * &lt;/p&gt;<a name="line.180"></a>
<FONT color="green">181</FONT>         * <a name="line.181"></a>
<FONT color="green">182</FONT>         * @param lineLength<a name="line.182"></a>
<FONT color="green">183</FONT>         *            Each line of encoded data will be at most of the given length (rounded down to nearest multiple of 8).<a name="line.183"></a>
<FONT color="green">184</FONT>         *            If lineLength &lt;= 0, then the output will not be divided into lines (chunks). Ignored when decoding.<a name="line.184"></a>
<FONT color="green">185</FONT>         */<a name="line.185"></a>
<FONT color="green">186</FONT>        public Base32(int lineLength) {<a name="line.186"></a>
<FONT color="green">187</FONT>            this(lineLength, CHUNK_SEPARATOR);<a name="line.187"></a>
<FONT color="green">188</FONT>        }<a name="line.188"></a>
<FONT color="green">189</FONT>    <a name="line.189"></a>
<FONT color="green">190</FONT>        /**<a name="line.190"></a>
<FONT color="green">191</FONT>         * Creates a Base32 codec used for decoding and encoding.<a name="line.191"></a>
<FONT color="green">192</FONT>         * &lt;p&gt;<a name="line.192"></a>
<FONT color="green">193</FONT>         * When encoding the line length and line separator are given in the constructor.<a name="line.193"></a>
<FONT color="green">194</FONT>         * &lt;/p&gt;<a name="line.194"></a>
<FONT color="green">195</FONT>         * &lt;p&gt;<a name="line.195"></a>
<FONT color="green">196</FONT>         * Line lengths that aren't multiples of 8 will still essentially end up being multiples of 8 in the encoded data.<a name="line.196"></a>
<FONT color="green">197</FONT>         * &lt;/p&gt;<a name="line.197"></a>
<FONT color="green">198</FONT>         * <a name="line.198"></a>
<FONT color="green">199</FONT>         * @param lineLength<a name="line.199"></a>
<FONT color="green">200</FONT>         *            Each line of encoded data will be at most of the given length (rounded down to nearest multiple of 8).<a name="line.200"></a>
<FONT color="green">201</FONT>         *            If lineLength &lt;= 0, then the output will not be divided into lines (chunks). Ignored when decoding.<a name="line.201"></a>
<FONT color="green">202</FONT>         * @param lineSeparator<a name="line.202"></a>
<FONT color="green">203</FONT>         *            Each line of encoded data will end with this sequence of bytes.<a name="line.203"></a>
<FONT color="green">204</FONT>         * @throws IllegalArgumentException<a name="line.204"></a>
<FONT color="green">205</FONT>         *             The provided lineSeparator included some Base32 characters. That's not going to work!<a name="line.205"></a>
<FONT color="green">206</FONT>         */<a name="line.206"></a>
<FONT color="green">207</FONT>        public Base32(int lineLength, byte[] lineSeparator) {<a name="line.207"></a>
<FONT color="green">208</FONT>            this(lineLength, lineSeparator, false);<a name="line.208"></a>
<FONT color="green">209</FONT>        }<a name="line.209"></a>
<FONT color="green">210</FONT>        <a name="line.210"></a>
<FONT color="green">211</FONT>        /**<a name="line.211"></a>
<FONT color="green">212</FONT>         * Creates a Base32 / Base32 Hex codec used for decoding and encoding.<a name="line.212"></a>
<FONT color="green">213</FONT>         * &lt;p&gt;<a name="line.213"></a>
<FONT color="green">214</FONT>         * When encoding the line length and line separator are given in the constructor.<a name="line.214"></a>
<FONT color="green">215</FONT>         * &lt;/p&gt;<a name="line.215"></a>
<FONT color="green">216</FONT>         * &lt;p&gt;<a name="line.216"></a>
<FONT color="green">217</FONT>         * Line lengths that aren't multiples of 8 will still essentially end up being multiples of 8 in the encoded data.<a name="line.217"></a>
<FONT color="green">218</FONT>         * &lt;/p&gt;<a name="line.218"></a>
<FONT color="green">219</FONT>         * <a name="line.219"></a>
<FONT color="green">220</FONT>         * @param lineLength<a name="line.220"></a>
<FONT color="green">221</FONT>         *            Each line of encoded data will be at most of the given length (rounded down to nearest multiple of 8).<a name="line.221"></a>
<FONT color="green">222</FONT>         *            If lineLength &lt;= 0, then the output will not be divided into lines (chunks). Ignored when decoding.<a name="line.222"></a>
<FONT color="green">223</FONT>         * @param lineSeparator<a name="line.223"></a>
<FONT color="green">224</FONT>         *            Each line of encoded data will end with this sequence of bytes.<a name="line.224"></a>
<FONT color="green">225</FONT>         * @param useHex if &lt;code&gt;true&lt;/code&gt;, then use Base32 Hex alphabet, otherwise use Base32 alphabet<a name="line.225"></a>
<FONT color="green">226</FONT>         * @throws IllegalArgumentException<a name="line.226"></a>
<FONT color="green">227</FONT>         *             The provided lineSeparator included some Base32 characters. That's not going to work!<a name="line.227"></a>
<FONT color="green">228</FONT>         *             Or the lineLength &gt; 0 and lineSeparator is null.<a name="line.228"></a>
<FONT color="green">229</FONT>         */<a name="line.229"></a>
<FONT color="green">230</FONT>        public Base32(int lineLength, byte[] lineSeparator, boolean useHex) {<a name="line.230"></a>
<FONT color="green">231</FONT>            super(BYTES_PER_UNENCODED_BLOCK, BYTES_PER_ENCODED_BLOCK, <a name="line.231"></a>
<FONT color="green">232</FONT>                    lineLength, <a name="line.232"></a>
<FONT color="green">233</FONT>                    lineSeparator == null ? 0 : lineSeparator.length);<a name="line.233"></a>
<FONT color="green">234</FONT>            if (useHex){<a name="line.234"></a>
<FONT color="green">235</FONT>                this.encodeTable = HEX_ENCODE_TABLE;<a name="line.235"></a>
<FONT color="green">236</FONT>                this.decodeTable = HEX_DECODE_TABLE;            <a name="line.236"></a>
<FONT color="green">237</FONT>            } else {<a name="line.237"></a>
<FONT color="green">238</FONT>                this.encodeTable = ENCODE_TABLE;<a name="line.238"></a>
<FONT color="green">239</FONT>                this.decodeTable = DECODE_TABLE;            <a name="line.239"></a>
<FONT color="green">240</FONT>            }<a name="line.240"></a>
<FONT color="green">241</FONT>            if (lineLength &gt; 0) {<a name="line.241"></a>
<FONT color="green">242</FONT>                if (lineSeparator == null) {<a name="line.242"></a>
<FONT color="green">243</FONT>                    throw new IllegalArgumentException("lineLength "+lineLength+" &gt; 0, but lineSeparator is null");<a name="line.243"></a>
<FONT color="green">244</FONT>                }<a name="line.244"></a>
<FONT color="green">245</FONT>                // Must be done after initializing the tables<a name="line.245"></a>
<FONT color="green">246</FONT>                if (containsAlphabetOrPad(lineSeparator)) {<a name="line.246"></a>
<FONT color="green">247</FONT>                    String sep = StringUtils.newStringUtf8(lineSeparator);<a name="line.247"></a>
<FONT color="green">248</FONT>                    throw new IllegalArgumentException("lineSeparator must not contain Base32 characters: [" + sep + "]");<a name="line.248"></a>
<FONT color="green">249</FONT>                }<a name="line.249"></a>
<FONT color="green">250</FONT>                this.encodeSize = BYTES_PER_ENCODED_BLOCK + lineSeparator.length;<a name="line.250"></a>
<FONT color="green">251</FONT>                this.lineSeparator = new byte[lineSeparator.length];<a name="line.251"></a>
<FONT color="green">252</FONT>                System.arraycopy(lineSeparator, 0, this.lineSeparator, 0, lineSeparator.length);<a name="line.252"></a>
<FONT color="green">253</FONT>            } else {<a name="line.253"></a>
<FONT color="green">254</FONT>                this.encodeSize = BYTES_PER_ENCODED_BLOCK;<a name="line.254"></a>
<FONT color="green">255</FONT>                this.lineSeparator = null;<a name="line.255"></a>
<FONT color="green">256</FONT>            }<a name="line.256"></a>
<FONT color="green">257</FONT>            this.decodeSize = this.encodeSize - 1;<a name="line.257"></a>
<FONT color="green">258</FONT>        }<a name="line.258"></a>
<FONT color="green">259</FONT>    <a name="line.259"></a>
<FONT color="green">260</FONT>        /**<a name="line.260"></a>
<FONT color="green">261</FONT>         * &lt;p&gt;<a name="line.261"></a>
<FONT color="green">262</FONT>         * Decodes all of the provided data, starting at inPos, for inAvail bytes. Should be called at least twice: once<a name="line.262"></a>
<FONT color="green">263</FONT>         * with the data to decode, and once with inAvail set to "-1" to alert decoder that EOF has been reached. The "-1"<a name="line.263"></a>
<FONT color="green">264</FONT>         * call is not necessary when decoding, but it doesn't hurt, either.<a name="line.264"></a>
<FONT color="green">265</FONT>         * &lt;/p&gt;<a name="line.265"></a>
<FONT color="green">266</FONT>         * &lt;p&gt;<a name="line.266"></a>
<FONT color="green">267</FONT>         * Ignores all non-Base32 characters. This is how chunked (e.g. 76 character) data is handled, since CR and LF are<a name="line.267"></a>
<FONT color="green">268</FONT>         * silently ignored, but has implications for other bytes, too. This method subscribes to the garbage-in,<a name="line.268"></a>
<FONT color="green">269</FONT>         * garbage-out philosophy: it will not check the provided data for validity.<a name="line.269"></a>
<FONT color="green">270</FONT>         * &lt;/p&gt;<a name="line.270"></a>
<FONT color="green">271</FONT>         * <a name="line.271"></a>
<FONT color="green">272</FONT>         * @param in<a name="line.272"></a>
<FONT color="green">273</FONT>         *            byte[] array of ascii data to Base32 decode.<a name="line.273"></a>
<FONT color="green">274</FONT>         * @param inPos<a name="line.274"></a>
<FONT color="green">275</FONT>         *            Position to start reading data from.<a name="line.275"></a>
<FONT color="green">276</FONT>         * @param inAvail<a name="line.276"></a>
<FONT color="green">277</FONT>         *            Amount of bytes available from input for encoding.<a name="line.277"></a>
<FONT color="green">278</FONT>         *<a name="line.278"></a>
<FONT color="green">279</FONT>         * Output is written to {@link #buffer} as 8-bit octets, using {@link pos} as the buffer position<a name="line.279"></a>
<FONT color="green">280</FONT>         */<a name="line.280"></a>
<FONT color="green">281</FONT>        void decode(byte[] in, int inPos, int inAvail) { // package protected for access from I/O streams<a name="line.281"></a>
<FONT color="green">282</FONT>            if (eof) {<a name="line.282"></a>
<FONT color="green">283</FONT>                return;<a name="line.283"></a>
<FONT color="green">284</FONT>            }<a name="line.284"></a>
<FONT color="green">285</FONT>            if (inAvail &lt; 0) {<a name="line.285"></a>
<FONT color="green">286</FONT>                eof = true;<a name="line.286"></a>
<FONT color="green">287</FONT>            }<a name="line.287"></a>
<FONT color="green">288</FONT>            for (int i = 0; i &lt; inAvail; i++) {<a name="line.288"></a>
<FONT color="green">289</FONT>                byte b = in[inPos++];<a name="line.289"></a>
<FONT color="green">290</FONT>                if (b == PAD) {<a name="line.290"></a>
<FONT color="green">291</FONT>                    // We're done.<a name="line.291"></a>
<FONT color="green">292</FONT>                    eof = true;<a name="line.292"></a>
<FONT color="green">293</FONT>                    break;<a name="line.293"></a>
<FONT color="green">294</FONT>                } else {<a name="line.294"></a>
<FONT color="green">295</FONT>                    ensureBufferSize(decodeSize);<a name="line.295"></a>
<FONT color="green">296</FONT>                    if (b &gt;= 0 &amp;&amp; b &lt; this.decodeTable.length) {<a name="line.296"></a>
<FONT color="green">297</FONT>                        int result = this.decodeTable[b];<a name="line.297"></a>
<FONT color="green">298</FONT>                        if (result &gt;= 0) {<a name="line.298"></a>
<FONT color="green">299</FONT>                            modulus = (modulus+1) % BYTES_PER_ENCODED_BLOCK;<a name="line.299"></a>
<FONT color="green">300</FONT>                            bitWorkArea = (bitWorkArea &lt;&lt; BITS_PER_ENCODED_BYTE) + result; // collect decoded bytes<a name="line.300"></a>
<FONT color="green">301</FONT>                            if (modulus == 0) { // we can output the 5 bytes<a name="line.301"></a>
<FONT color="green">302</FONT>                                buffer[pos++] = (byte) ((bitWorkArea &gt;&gt; 32) &amp; MASK_8BITS);<a name="line.302"></a>
<FONT color="green">303</FONT>                                buffer[pos++] = (byte) ((bitWorkArea &gt;&gt; 24) &amp; MASK_8BITS);<a name="line.303"></a>
<FONT color="green">304</FONT>                                buffer[pos++] = (byte) ((bitWorkArea &gt;&gt; 16) &amp; MASK_8BITS);<a name="line.304"></a>
<FONT color="green">305</FONT>                                buffer[pos++] = (byte) ((bitWorkArea &gt;&gt; 8) &amp; MASK_8BITS);<a name="line.305"></a>
<FONT color="green">306</FONT>                                buffer[pos++] = (byte) (bitWorkArea &amp; MASK_8BITS);<a name="line.306"></a>
<FONT color="green">307</FONT>                            }<a name="line.307"></a>
<FONT color="green">308</FONT>                        }<a name="line.308"></a>
<FONT color="green">309</FONT>                    }<a name="line.309"></a>
<FONT color="green">310</FONT>                }<a name="line.310"></a>
<FONT color="green">311</FONT>            }<a name="line.311"></a>
<FONT color="green">312</FONT>        <a name="line.312"></a>
<FONT color="green">313</FONT>            // Two forms of EOF as far as Base32 decoder is concerned: actual<a name="line.313"></a>
<FONT color="green">314</FONT>            // EOF (-1) and first time '=' character is encountered in stream.<a name="line.314"></a>
<FONT color="green">315</FONT>            // This approach makes the '=' padding characters completely optional.<a name="line.315"></a>
<FONT color="green">316</FONT>            if (eof &amp;&amp; modulus &gt;= 2) { // if modulus &lt; 2, nothing to do<a name="line.316"></a>
<FONT color="green">317</FONT>                ensureBufferSize(decodeSize);<a name="line.317"></a>
<FONT color="green">318</FONT>        <a name="line.318"></a>
<FONT color="green">319</FONT>                //  we ignore partial bytes, i.e. only multiples of 8 count<a name="line.319"></a>
<FONT color="green">320</FONT>                switch (modulus) {<a name="line.320"></a>
<FONT color="green">321</FONT>                    case 2 : // 10 bits, drop 2 and output one byte<a name="line.321"></a>
<FONT color="green">322</FONT>                        buffer[pos++] = (byte) ((bitWorkArea &gt;&gt; 2) &amp; MASK_8BITS);<a name="line.322"></a>
<FONT color="green">323</FONT>                        break;<a name="line.323"></a>
<FONT color="green">324</FONT>                    case 3 : // 15 bits, drop 7 and output 1 byte<a name="line.324"></a>
<FONT color="green">325</FONT>                        buffer[pos++] = (byte) ((bitWorkArea &gt;&gt; 7) &amp; MASK_8BITS);<a name="line.325"></a>
<FONT color="green">326</FONT>                        break;<a name="line.326"></a>
<FONT color="green">327</FONT>                    case 4 : // 20 bits = 2*8 + 4<a name="line.327"></a>
<FONT color="green">328</FONT>                        bitWorkArea = bitWorkArea &gt;&gt; 4; // drop 4 bits<a name="line.328"></a>
<FONT color="green">329</FONT>                        buffer[pos++] = (byte) ((bitWorkArea &gt;&gt; 8) &amp; MASK_8BITS);<a name="line.329"></a>
<FONT color="green">330</FONT>                        buffer[pos++] = (byte) ((bitWorkArea) &amp; MASK_8BITS);<a name="line.330"></a>
<FONT color="green">331</FONT>                        break;<a name="line.331"></a>
<FONT color="green">332</FONT>                    case 5 : // 25bits = 3*8 + 1<a name="line.332"></a>
<FONT color="green">333</FONT>                        bitWorkArea = bitWorkArea &gt;&gt; 1;<a name="line.333"></a>
<FONT color="green">334</FONT>                        buffer[pos++] = (byte) ((bitWorkArea &gt;&gt; 16) &amp; MASK_8BITS);<a name="line.334"></a>
<FONT color="green">335</FONT>                        buffer[pos++] = (byte) ((bitWorkArea &gt;&gt; 8) &amp; MASK_8BITS);<a name="line.335"></a>
<FONT color="green">336</FONT>                        buffer[pos++] = (byte) ((bitWorkArea) &amp; MASK_8BITS);<a name="line.336"></a>
<FONT color="green">337</FONT>                        break;<a name="line.337"></a>
<FONT color="green">338</FONT>                    case 6 : // 30bits = 3*8 + 6<a name="line.338"></a>
<FONT color="green">339</FONT>                        bitWorkArea = bitWorkArea &gt;&gt; 6;<a name="line.339"></a>
<FONT color="green">340</FONT>                        buffer[pos++] = (byte) ((bitWorkArea &gt;&gt; 16) &amp; MASK_8BITS);<a name="line.340"></a>
<FONT color="green">341</FONT>                        buffer[pos++] = (byte) ((bitWorkArea &gt;&gt; 8) &amp; MASK_8BITS);<a name="line.341"></a>
<FONT color="green">342</FONT>                        buffer[pos++] = (byte) ((bitWorkArea) &amp; MASK_8BITS);<a name="line.342"></a>
<FONT color="green">343</FONT>                        break;<a name="line.343"></a>
<FONT color="green">344</FONT>                    case 7 : // 35 = 4*8 +3<a name="line.344"></a>
<FONT color="green">345</FONT>                        bitWorkArea = bitWorkArea &gt;&gt; 3;<a name="line.345"></a>
<FONT color="green">346</FONT>                        buffer[pos++] = (byte) ((bitWorkArea &gt;&gt; 24) &amp; MASK_8BITS);<a name="line.346"></a>
<FONT color="green">347</FONT>                        buffer[pos++] = (byte) ((bitWorkArea &gt;&gt; 16) &amp; MASK_8BITS);<a name="line.347"></a>
<FONT color="green">348</FONT>                        buffer[pos++] = (byte) ((bitWorkArea &gt;&gt; 8) &amp; MASK_8BITS);<a name="line.348"></a>
<FONT color="green">349</FONT>                        buffer[pos++] = (byte) ((bitWorkArea) &amp; MASK_8BITS);<a name="line.349"></a>
<FONT color="green">350</FONT>                        break;<a name="line.350"></a>
<FONT color="green">351</FONT>                }<a name="line.351"></a>
<FONT color="green">352</FONT>            }<a name="line.352"></a>
<FONT color="green">353</FONT>        }<a name="line.353"></a>
<FONT color="green">354</FONT>    <a name="line.354"></a>
<FONT color="green">355</FONT>        /**<a name="line.355"></a>
<FONT color="green">356</FONT>         * &lt;p&gt;<a name="line.356"></a>
<FONT color="green">357</FONT>         * Encodes all of the provided data, starting at inPos, for inAvail bytes. Must be called at least twice: once with<a name="line.357"></a>
<FONT color="green">358</FONT>         * the data to encode, and once with inAvail set to "-1" to alert encoder that EOF has been reached, so flush last<a name="line.358"></a>
<FONT color="green">359</FONT>         * remaining bytes (if not multiple of 5).<a name="line.359"></a>
<FONT color="green">360</FONT>         * &lt;/p&gt;<a name="line.360"></a>
<FONT color="green">361</FONT>         * <a name="line.361"></a>
<FONT color="green">362</FONT>         * @param in<a name="line.362"></a>
<FONT color="green">363</FONT>         *            byte[] array of binary data to Base32 encode.<a name="line.363"></a>
<FONT color="green">364</FONT>         * @param inPos<a name="line.364"></a>
<FONT color="green">365</FONT>         *            Position to start reading data from.<a name="line.365"></a>
<FONT color="green">366</FONT>         * @param inAvail<a name="line.366"></a>
<FONT color="green">367</FONT>         *            Amount of bytes available from input for encoding.<a name="line.367"></a>
<FONT color="green">368</FONT>         */<a name="line.368"></a>
<FONT color="green">369</FONT>        void encode(byte[] in, int inPos, int inAvail) { // package protected for access from I/O streams<a name="line.369"></a>
<FONT color="green">370</FONT>            if (eof) {<a name="line.370"></a>
<FONT color="green">371</FONT>                return;<a name="line.371"></a>
<FONT color="green">372</FONT>            }<a name="line.372"></a>
<FONT color="green">373</FONT>            // inAvail &lt; 0 is how we're informed of EOF in the underlying data we're<a name="line.373"></a>
<FONT color="green">374</FONT>            // encoding.<a name="line.374"></a>
<FONT color="green">375</FONT>            if (inAvail &lt; 0) {<a name="line.375"></a>
<FONT color="green">376</FONT>                eof = true;<a name="line.376"></a>
<FONT color="green">377</FONT>                if (0 == modulus &amp;&amp; lineLength == 0) {<a name="line.377"></a>
<FONT color="green">378</FONT>                    return; // no leftovers to process and not using chunking<a name="line.378"></a>
<FONT color="green">379</FONT>                }<a name="line.379"></a>
<FONT color="green">380</FONT>                ensureBufferSize(encodeSize);<a name="line.380"></a>
<FONT color="green">381</FONT>                int savedPos = pos;<a name="line.381"></a>
<FONT color="green">382</FONT>                switch (modulus) { // % 5<a name="line.382"></a>
<FONT color="green">383</FONT>                    case 1 : // Only 1 octet; take top 5 bits then remainder<a name="line.383"></a>
<FONT color="green">384</FONT>                        buffer[pos++] = encodeTable[(int)(bitWorkArea &gt;&gt; 3) &amp; MASK_5BITS]; // 8-1*5 = 3<a name="line.384"></a>
<FONT color="green">385</FONT>                        buffer[pos++] = encodeTable[(int)(bitWorkArea &lt;&lt; 2) &amp; MASK_5BITS]; // 5-3=2<a name="line.385"></a>
<FONT color="green">386</FONT>                        buffer[pos++] = PAD;<a name="line.386"></a>
<FONT color="green">387</FONT>                        buffer[pos++] = PAD;<a name="line.387"></a>
<FONT color="green">388</FONT>                        buffer[pos++] = PAD;<a name="line.388"></a>
<FONT color="green">389</FONT>                        buffer[pos++] = PAD;<a name="line.389"></a>
<FONT color="green">390</FONT>                        buffer[pos++] = PAD;<a name="line.390"></a>
<FONT color="green">391</FONT>                        buffer[pos++] = PAD;<a name="line.391"></a>
<FONT color="green">392</FONT>                        break;<a name="line.392"></a>
<FONT color="green">393</FONT>        <a name="line.393"></a>
<FONT color="green">394</FONT>                    case 2 : // 2 octets = 16 bits to use<a name="line.394"></a>
<FONT color="green">395</FONT>                        buffer[pos++] = encodeTable[(int)(bitWorkArea &gt;&gt; 11) &amp; MASK_5BITS]; // 16-1*5 = 11<a name="line.395"></a>
<FONT color="green">396</FONT>                        buffer[pos++] = encodeTable[(int)(bitWorkArea &gt;&gt;  6) &amp; MASK_5BITS]; // 16-2*5 = 6<a name="line.396"></a>
<FONT color="green">397</FONT>                        buffer[pos++] = encodeTable[(int)(bitWorkArea &gt;&gt;  1) &amp; MASK_5BITS]; // 16-3*5 = 1<a name="line.397"></a>
<FONT color="green">398</FONT>                        buffer[pos++] = encodeTable[(int)(bitWorkArea &lt;&lt;  4) &amp; MASK_5BITS]; // 5-1 = 4<a name="line.398"></a>
<FONT color="green">399</FONT>                        buffer[pos++] = PAD;<a name="line.399"></a>
<FONT color="green">400</FONT>                        buffer[pos++] = PAD;<a name="line.400"></a>
<FONT color="green">401</FONT>                        buffer[pos++] = PAD;<a name="line.401"></a>
<FONT color="green">402</FONT>                        buffer[pos++] = PAD;<a name="line.402"></a>
<FONT color="green">403</FONT>                        break;<a name="line.403"></a>
<FONT color="green">404</FONT>                    case 3 : // 3 octets = 24 bits to use<a name="line.404"></a>
<FONT color="green">405</FONT>                        buffer[pos++] = encodeTable[(int)(bitWorkArea &gt;&gt; 19) &amp; MASK_5BITS]; // 24-1*5 = 19<a name="line.405"></a>
<FONT color="green">406</FONT>                        buffer[pos++] = encodeTable[(int)(bitWorkArea &gt;&gt; 14) &amp; MASK_5BITS]; // 24-2*5 = 14<a name="line.406"></a>
<FONT color="green">407</FONT>                        buffer[pos++] = encodeTable[(int)(bitWorkArea &gt;&gt;  9) &amp; MASK_5BITS]; // 24-3*5 = 9<a name="line.407"></a>
<FONT color="green">408</FONT>                        buffer[pos++] = encodeTable[(int)(bitWorkArea &gt;&gt;  4) &amp; MASK_5BITS]; // 24-4*5 = 4<a name="line.408"></a>
<FONT color="green">409</FONT>                        buffer[pos++] = encodeTable[(int)(bitWorkArea &lt;&lt;  1) &amp; MASK_5BITS]; // 5-4 = 1<a name="line.409"></a>
<FONT color="green">410</FONT>                        buffer[pos++] = PAD;<a name="line.410"></a>
<FONT color="green">411</FONT>                        buffer[pos++] = PAD;<a name="line.411"></a>
<FONT color="green">412</FONT>                        buffer[pos++] = PAD;<a name="line.412"></a>
<FONT color="green">413</FONT>                        break;<a name="line.413"></a>
<FONT color="green">414</FONT>                    case 4 : // 4 octets = 32 bits to use<a name="line.414"></a>
<FONT color="green">415</FONT>                        buffer[pos++] = encodeTable[(int)(bitWorkArea &gt;&gt; 27) &amp; MASK_5BITS]; // 32-1*5 = 27<a name="line.415"></a>
<FONT color="green">416</FONT>                        buffer[pos++] = encodeTable[(int)(bitWorkArea &gt;&gt; 22) &amp; MASK_5BITS]; // 32-2*5 = 22<a name="line.416"></a>
<FONT color="green">417</FONT>                        buffer[pos++] = encodeTable[(int)(bitWorkArea &gt;&gt; 17) &amp; MASK_5BITS]; // 32-3*5 = 17<a name="line.417"></a>
<FONT color="green">418</FONT>                        buffer[pos++] = encodeTable[(int)(bitWorkArea &gt;&gt; 12) &amp; MASK_5BITS]; // 32-4*5 = 12<a name="line.418"></a>
<FONT color="green">419</FONT>                        buffer[pos++] = encodeTable[(int)(bitWorkArea &gt;&gt;  7) &amp; MASK_5BITS]; // 32-5*5 =  7<a name="line.419"></a>
<FONT color="green">420</FONT>                        buffer[pos++] = encodeTable[(int)(bitWorkArea &gt;&gt;  2) &amp; MASK_5BITS]; // 32-6*5 =  2<a name="line.420"></a>
<FONT color="green">421</FONT>                        buffer[pos++] = encodeTable[(int)(bitWorkArea &lt;&lt;  3) &amp; MASK_5BITS]; // 5-2 = 3<a name="line.421"></a>
<FONT color="green">422</FONT>                        buffer[pos++] = PAD;<a name="line.422"></a>
<FONT color="green">423</FONT>                        break;<a name="line.423"></a>
<FONT color="green">424</FONT>                }<a name="line.424"></a>
<FONT color="green">425</FONT>                currentLinePos += pos - savedPos; // keep track of current line position<a name="line.425"></a>
<FONT color="green">426</FONT>                // if currentPos == 0 we are at the start of a line, so don't add CRLF<a name="line.426"></a>
<FONT color="green">427</FONT>                if (lineLength &gt; 0 &amp;&amp; currentLinePos &gt; 0){ // add chunk separator if required<a name="line.427"></a>
<FONT color="green">428</FONT>                    System.arraycopy(lineSeparator, 0, buffer, pos, lineSeparator.length);<a name="line.428"></a>
<FONT color="green">429</FONT>                    pos += lineSeparator.length;<a name="line.429"></a>
<FONT color="green">430</FONT>                }            <a name="line.430"></a>
<FONT color="green">431</FONT>            } else {<a name="line.431"></a>
<FONT color="green">432</FONT>                for (int i = 0; i &lt; inAvail; i++) {<a name="line.432"></a>
<FONT color="green">433</FONT>                    ensureBufferSize(encodeSize);<a name="line.433"></a>
<FONT color="green">434</FONT>                    modulus = (modulus+1) % BYTES_PER_UNENCODED_BLOCK;<a name="line.434"></a>
<FONT color="green">435</FONT>                    int b = in[inPos++];<a name="line.435"></a>
<FONT color="green">436</FONT>                    if (b &lt; 0) {<a name="line.436"></a>
<FONT color="green">437</FONT>                        b += 256;<a name="line.437"></a>
<FONT color="green">438</FONT>                    }<a name="line.438"></a>
<FONT color="green">439</FONT>                    bitWorkArea = (bitWorkArea &lt;&lt; 8) + b; // BITS_PER_BYTE<a name="line.439"></a>
<FONT color="green">440</FONT>                    if (0 == modulus) { // we have enough bytes to create our output <a name="line.440"></a>
<FONT color="green">441</FONT>                        buffer[pos++] = encodeTable[(int)(bitWorkArea &gt;&gt; 35) &amp; MASK_5BITS];<a name="line.441"></a>
<FONT color="green">442</FONT>                        buffer[pos++] = encodeTable[(int)(bitWorkArea &gt;&gt; 30) &amp; MASK_5BITS];<a name="line.442"></a>
<FONT color="green">443</FONT>                        buffer[pos++] = encodeTable[(int)(bitWorkArea &gt;&gt; 25) &amp; MASK_5BITS];<a name="line.443"></a>
<FONT color="green">444</FONT>                        buffer[pos++] = encodeTable[(int)(bitWorkArea &gt;&gt; 20) &amp; MASK_5BITS];<a name="line.444"></a>
<FONT color="green">445</FONT>                        buffer[pos++] = encodeTable[(int)(bitWorkArea &gt;&gt; 15) &amp; MASK_5BITS];<a name="line.445"></a>
<FONT color="green">446</FONT>                        buffer[pos++] = encodeTable[(int)(bitWorkArea &gt;&gt; 10) &amp; MASK_5BITS];<a name="line.446"></a>
<FONT color="green">447</FONT>                        buffer[pos++] = encodeTable[(int)(bitWorkArea &gt;&gt; 5) &amp; MASK_5BITS];<a name="line.447"></a>
<FONT color="green">448</FONT>                        buffer[pos++] = encodeTable[(int)bitWorkArea &amp; MASK_5BITS];<a name="line.448"></a>
<FONT color="green">449</FONT>                        currentLinePos += BYTES_PER_ENCODED_BLOCK;<a name="line.449"></a>
<FONT color="green">450</FONT>                        if (lineLength &gt; 0 &amp;&amp; lineLength &lt;= currentLinePos) {<a name="line.450"></a>
<FONT color="green">451</FONT>                            System.arraycopy(lineSeparator, 0, buffer, pos, lineSeparator.length);<a name="line.451"></a>
<FONT color="green">452</FONT>                            pos += lineSeparator.length;<a name="line.452"></a>
<FONT color="green">453</FONT>                            currentLinePos = 0;<a name="line.453"></a>
<FONT color="green">454</FONT>                        }<a name="line.454"></a>
<FONT color="green">455</FONT>                    }<a name="line.455"></a>
<FONT color="green">456</FONT>                }<a name="line.456"></a>
<FONT color="green">457</FONT>            }<a name="line.457"></a>
<FONT color="green">458</FONT>        }<a name="line.458"></a>
<FONT color="green">459</FONT>    <a name="line.459"></a>
<FONT color="green">460</FONT>        /**<a name="line.460"></a>
<FONT color="green">461</FONT>         * Returns whether or not the &lt;code&gt;octet&lt;/code&gt; is in the Base32 alphabet.<a name="line.461"></a>
<FONT color="green">462</FONT>         * <a name="line.462"></a>
<FONT color="green">463</FONT>         * @param octet<a name="line.463"></a>
<FONT color="green">464</FONT>         *            The value to test<a name="line.464"></a>
<FONT color="green">465</FONT>         * @return &lt;code&gt;true&lt;/code&gt; if the value is defined in the the Base32 alphabet &lt;code&gt;false&lt;/code&gt; otherwise.<a name="line.465"></a>
<FONT color="green">466</FONT>         */<a name="line.466"></a>
<FONT color="green">467</FONT>        public boolean isInAlphabet(byte octet) {<a name="line.467"></a>
<FONT color="green">468</FONT>            return octet &gt;= 0 &amp;&amp; octet &lt; decodeTable.length &amp;&amp; decodeTable[octet] != -1;<a name="line.468"></a>
<FONT color="green">469</FONT>        }<a name="line.469"></a>
<FONT color="green">470</FONT>    }<a name="line.470"></a>




























































</PRE>
</BODY>
</HTML>
